package com.yuelife.service.impl;

import com.yuelife.entity.CUserlikes;
import com.yuelife.dao.CUserlikesDao;
import com.yuelife.service.CUserlikesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CUserlikes)表服务实现类
 *
 * @author makejava
 * @since 2020-06-18 10:11:58
 */
@Service("cUserlikesService")
public class CUserlikesServiceImpl implements CUserlikesService {
    @Resource
    private CUserlikesDao cUserlikesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CUserlikes queryById(Integer id) {
        return this.cUserlikesDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<CUserlikes> queryAllByLimit(int offset, int limit) {
        return this.cUserlikesDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param cUserlikes 实例对象
     * @return 实例对象
     */
    @Override
    public CUserlikes insert(CUserlikes cUserlikes) {
        this.cUserlikesDao.insert(cUserlikes);
        return cUserlikes;
    }

    /**
     * 修改数据
     *
     * @param cUserlikes 实例对象
     * @return 实例对象
     */
    @Override
    public CUserlikes update(CUserlikes cUserlikes) {
        this.cUserlikesDao.update(cUserlikes);
        return this.queryById(cUserlikes.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.cUserlikesDao.deleteById(id) > 0;
    }

    @Override
    public List<CUserlikes> selectAllUserLiskes(Integer userid) {
        CUserlikes userlikes = new CUserlikes();
        userlikes.setUserId(userid);
        return cUserlikesDao.queryAll(userlikes);
    }

    @Override
    public boolean deleteLike(CUserlikes userlikes) {
        System.out.println(userlikes.toString());
        int i = cUserlikesDao.deleteLike(userlikes);
        return  i>0?true:false;
    }


}